<template>
    <div class="photoinfo-container">
        <h2 class="title">{{ photoInfo.title }}</h2>
        <p class="subtitle">
            <span>发表时间: {{ photoInfo.add_time }}</span>
            <span>点击：{{ photoInfo.click }}次</span>
        </p>

        <!-- 图片预览 -->
        <vue-preview :slides="slide1" @close="handleClose" class="photo-preview" width="100px"></vue-preview>
        <!--<img class="preview-img" v-for="(item, index) in slide1" :src="item.src" height="100" @click="$preview.open(index, list)">-->
        <!-- 发表内容 -->
        <div class="content" v-html="photoInfo.content">
        </div>

        <!-- 评论 -->
        <cmt-box :id="id"></cmt-box>
    </div>
</template>

<script>
    import comment from '../subcomponents/Comment.vue'
    export default {
        data () {
            return {
                id: this.$route.params.id,
                photoInfo: {},
                slide1: []
            }
        },
        created () {
            this.getPhotoInfo();
            this.getPhotoPreview();
        },
        methods: {
            getPhotoInfo() {
                this.$http.get('home/PhotoInfo.json?id=' + this.id).then( result => {
                   if (result.body.status === 0) {
                       this.photoInfo = result.body.message[0];
                   }
                });
            },
            // 获取预览图片
            getPhotoPreview() {
                this.$http.get('home/PhotoPreview.json?id=' + this.id).then( result => {
                    if (result.body.status === 0) {
                        // 循环每一项，赋值宽和高
                        result.body.message.forEach( item => {
                            item.w = 600;
                            item.h = 400
                        });
                        this.slide1 = result.body.message;
                    }
                })
            },
            // vue-preview需要自定义的方法
            handleClose () {
                console.log('close event')
            }
        },
        components: {
            'cmt-box': comment
        }
    }
</script>

<style lang="scss" scoped>
.photoinfo-container {
    padding: 3px;
    h2 {
        font-size: 14px;
        text-align: center;
        color: dodgerblue;
        margin: 10px 0;
    }
    .subtitle {
        font-size: 13px;
        display: flex;
        justify-content: space-between;
    }
    .content {
        font-size: 13px;
        text-indent: 2em;
        margin-bottom: 10px;
        line-height: 30px;
    }

    .photo-preview {
        img {
            width: 30px;
            height: 30px;
        }
    }
}
</style>
